package com.toobigtofail
{
	import flash.geom.Rectangle;
	
	import net.flashpunk.Entity;
	import net.flashpunk.FP;
	import net.flashpunk.Graphic;
	import net.flashpunk.Mask;
	import net.flashpunk.graphics.Canvas;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.tweens.misc.NumTween;
	
	public class Scene extends Entity
	{
		public var backgroundColor:uint;
		public var image:Image;
		public var alphaTween:NumTween = new NumTween(fadeInComplete);
		private var _textValue:String = "";
		private var _onscreen:Boolean = false;
		
		private var _containedEntities:Array = [];
		
		public function Scene(x:Number=0,
							  y:Number=0,
							  width:int=0,
							  height:int=0,
							  backgroundColor:uint=0x000000,
							  text:String=null,
							  graphic:Graphic=null,
							  mask:Mask=null)
		{
			addTween(alphaTween);
			alphaTween.tween(0,1,2);
			this.x = x;
			this.y = y;
			this.width = width;
			this.height = height;
			this.backgroundColor = backgroundColor;
			this.text = text;
			graphic = image = Image.createRect(width, height, backgroundColor);
			/*var myCanvas:Canvas = new Canvas(this.width, this.height);
			myCanvas.drawRect(new Rectangle(0,0,width,height), backgroundColor, 1);
			myCanvas.
			graphic = 
		*/
			
			super(x, y, graphic, mask);
		}
		
		override public function added():void
		{
			this.image.alpha = 0;
			for each (var i:SceneEntity in _containedEntities)
			{
				FP.world.add(i);
				i.image.alpha = 0;
			}
			alphaTween.start();
			
		}
		
		override public function update():void
		{
			super.update();
			this.image.alpha = alphaTween.value;
			for each (var i:SceneEntity in _containedEntities)
			{
				i.image.alpha = alphaTween.value;
			}
			
		}
		
		private function fadeInComplete():void
		{
			
		}
		
		private function fadeOutComplete():void
		{
			for each (var j:SceneEntity in _containedEntities)
			{
				FP.world.remove(j);
			}
			//insert saveState stuff here
			
			FP.world.remove(this);
			
		}
		
		
		public function set text(value:String):void { _textValue = value; }
		public function get text():String { return _textValue; }
	}
}